package com.zhangbo.week02.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zhangbo.week02.entity.Columne;
import com.zhangbo.week02.service.ColumneService;

@Controller
public class ColumneController {

	@Autowired
	ColumneService ser;

	@RequestMapping("ToList")
	private String GetList(HttpServletRequest request, Columne columne) {
		List<Columne> list = ser.getList();
		request.setAttribute("list", list);
		request.setAttribute("cname", columne.getCname());

		return "List";
	}

	@RequestMapping("ToShenHe/{cid}")
	private String ToShenHe(@PathVariable("cid") int cid, HttpServletRequest request) {
		List<Columne> listi = ser.getListById(cid);
		request.setAttribute("listi", listi);
		return "ShenHe";
	}

	@RequestMapping("ToUpdate")
	@ResponseBody
	private int ShenHe(Columne columne) {
		int shenHe = ser.ShenHe(columne);
		if (shenHe > 0) {
			return 1;
		}
		return 0;
	}
}
